#! /usr/bin/env python

VERSION='0.1'
APPNAME='crash'

srcdir = '.'
blddir = 'build'

import sys, re, os
import waf_dynamo, waf_ddf
import waflib.Options
import TestContext
from build_constants import TargetOS

test_context = None

def init(ctx):
    global test_context
    if 'build' in waflib.Options.commands:
        test_context = TestContext.create_test_context()

def options(opt):
    opt.load('waf_dynamo')
    opt.load('waf_ddf')

def configure(conf):
    conf.load('waf_dynamo')
    conf.load('waf_ddf')
    waf_ddf.configure(conf)

    conf.recurse('src')
    target_os = conf.env['TARGET_OS']

    conf.env.append_value('CPPPATH', "default/src")

    conf.env['STLIB_DLIB'] = ['dlib', 'mbedtls', 'zip']
    conf.env['STLIB_DDF'] = 'ddf'
    conf.env['STLIB_RESOURCE'] = 'resource'
    conf.env['STLIB_EXTENSION'] = 'extension'
    conf.env['STLIB_SCRIPT'] = 'script'

    if target_os != TargetOS.MACOS:
        conf.env['STLIB_UNWIND'] = 'unwind'

    conf.env.append_unique('DEFINES', 'DLIB_LOG_DOMAIN="CRASH"')

    if target_os == TargetOS.WINDOWS:
        conf.env.append_value('LINKFLAGS', ['dbghelp.lib'])

def build(bld):
    global test_context
    bld.recurse('src')
    TestContext.initialize_test_context(test_context, bld)

def shutdown(self):
    waf_dynamo.run_tests(test_context, valgrind = True)
